<%@ page language="java" contentType="application/vnd.ms-excel; charset=UTF-8" %>
<%@ page import="weaver.hrm.report.schedulediff.HrmScheduleDiffManager"%>
<%@ page import="weaver.systeminfo.*,java.util.*,weaver.hrm.*" %>
<%@ page import="weaver.general.Util,weaver.hrm.common.*" %>
<%@ page import="weaver.hrm.attendance.domain.*"%>
<!-- modified by wcd 2014-07-24 [E7 to E8] -->
<jsp:useBean id="colorManager" class="weaver.hrm.attendance.manager.HrmLeaveTypeColorManager" scope="page" />
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs2" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="strUtil" class="weaver.common.StringUtil" scope="page"/>
<jsp:useBean id="dateUtil" class="weaver.common.DateUtil" scope="page"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
	User user = HrmUserVarify.getUser (request , response) ;
	if(user == null)  return ;
	response.setContentType("application/vnd.ms-excel");
	
	Calendar today = Calendar.getInstance ();
	String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-"
					   + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-"
					   + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2);//当前时间

	String cmd = strUtil.vString(request.getParameter("cmd"));//用于区分
	String fromDate = strUtil.vString(request.getParameter("fromDate"));//开始时间
	String toDate = strUtil.vString(request.getParameter("toDate"));//结束时间
	
	
	String XMNo = Util.null2String(request.getParameter("XMNo"));//项目编号
	
	String tnum = strUtil.vString(request.getParameter("tnum"));
	String subCompanyId = strUtil.vString(request.getParameter("subCompanyId"));//分部id
	String departmentId = strUtil.vString(request.getParameter("departmentId"));//部门id
	String resourceId = strUtil.vString(request.getParameter("resourceId"));//人员id
	String status = strUtil.vString(request.getParameter("status"));//状态id
	//非考勤管理员只能看到自己的记录
	if(!HrmUserVarify.checkUserRight("BohaiInsuranceScheduleReport:View", user)){
		resourceId = String.valueOf(user.getUID());
	}
	String fileName = "项目部报表";
	response.setHeader("Content-disposition","attachment;filename="+new String(fileName.getBytes("GBK"),"iso8859-1")+".xls");
%>
<%
	if(cmd.equals("CheckWorkAttendance")){
%>
<table  border=1  bordercolor=black style="border-collapse:collapse;" width="100%" >
	<tbody>
		<tr>
			<td align="center" colspan="12"><%=fileName%></td>
		</tr>
		<tr>
			<td align="center" colspan="8">项目信息</td>
			<td align="center" colspan="1">项目进度</td>
			<!--<td align="center" colspan="6">隐蔽工程信息</td>
			<td align="center" colspan="4">第三方检测</td>-->
			<td align="center" colspan="3">项目竣工文件</td>
			<!--<td></td>-->
		</tr>
		<tr>
			<td align="center">序号</td>
			<td align="center">项目编号</td>
			<td align="center">项目名称</td>
			<td align="center">项目区域</td>
			<td align="center">甲方项目经理</td>
			<td align="center">设计公司</td>
			<td align="center">项目经理</td>
			<td align="center">施工班组</td>
			
			<td align="center">入场时间</td>
			<!--<td align="center">设备到货时间</td>
			<td align="center">交铺时间</td>
			<td align="center">项目现状</td>
			<td align="center">项目进度</td>
			
			<td align="center">给水试压</td>
			<td align="center">排水管道走向</td>
			<td align="center">防水区域试水</td>
			<td align="center">楼梯踏步图片</td>
			<td align="center">电柜绝缘测试</td>
			<td align="center">完工天花内检查</td>
			
			<td align="center">热水器/空调设备调试</td>
			<td align="center">防鼠验收</td>
			<td align="center">油烟机及管道验收</td>
			<td align="center">空调保养单位验收</td>-->
			
			<td align="center">竣工图纸</td>
			<td align="center">竣工资料</td>
			<td align="center">竣工图片</td>
			<!--<td align="center">移交维修部情况</td>
			
			<td align="center">备注</td>-->
		</tr>
		<%
			String sql = "select a.xmbh,a.xmmc,f.selectname,a.xmjflxr,e.selectname sjgs,g.lastname,c.kgsj,d.wcsj18,d.wcsj20,d.wcsj19";
			sql += " from formtable_main_42 a left join formtable_main_48 b on a.xmbh=b.xmbh left join formtable_main_54 c on a.xmbh=c.xmbh left join formtable_main_59 d on a.xmbh=d.xmbh";
			sql += " left join (select selectvalue,selectname from workflow_selectitem where fieldid='9697') f on a.scqy=f.selectvalue";
			sql += " left join HrmResource g on c.xmjl=g.id left join (select selectvalue,selectname from workflow_selectitem where fieldid='7164') e on b.sjgs=e.selectvalue";
			
			if(!fromDate.equals("") && !toDate.equals("")){
				sql += " where a.sqrq between '"+fromDate+"' and '"+toDate+"'";
			}else if(!fromDate.equals("")){
				sql += " where a.sqrq='"+fromDate+"'";
			}else if(!toDate.equals("")){
				sql += " where a.sqrq='"+toDate+"'";
			}
			
			if(!fromDate.equals("") || !toDate.equals("")){
				if(!XMNo.equals("")){
					sql += " and a.xmbh like '%"+XMNo+"%'";
				}
			}else{
				if(!XMNo.equals("")){
					sql += " where a.xmbh like '%"+XMNo+"%'";
				}else{
					sql += " where a.xmbh='21321323213421414421'";
				}
			}
			
			sql += " order by a.xmbh";
			rs.executeSql(sql);
			int xh = 0;
			while(rs.next()){
				out.print("<tr>");
				xh = xh+1;
				String xmbh = strUtil.vString(rs.getString("xmbh"));
				out.print("<td align='center'>"+xh+"</td>");//
				out.print("<td align='center'>"+xmbh+"</td>");//项目编号
				out.print("<td align='center'>"+rs.getString("xmmc")+"</td>");//项目名称
				out.print("<td align='center'>"+rs.getString("selectname")+"</td>");//项目区域
				out.print("<td align='center'>"+rs.getString("xmjflxr")+"</td>");//甲方项目经理
				out.print("<td align='center'>"+rs.getString("sjgs")+"</td>");//设计公司
				out.print("<td align='center'>"+rs.getString("lastname")+"</td>");//项目经理
				
				String sgbz = "";
				String bzxm = "";
				String kgbgSql = "select bzxm from formtable_main_48 a,formtable_main_48_dt1 b where a.id=b.mainid and a.xmbh='"+xmbh+"'";
				rs1.executeSql(kgbgSql);
				while(rs1.next()){
					 String a = strUtil.vString(rs1.getString("bzxm"));
					 if(!bzxm.equals(a)){
						bzxm = a;
						String hrmSql = "select lastname from HrmResource where id='"+bzxm+"'";
						rs2.executeSql(hrmSql);
						while(rs2.next()){
							if(!sgbz.equals("")){
								sgbz += ","+strUtil.vString(rs2.getString("lastname"));
							}else{
								sgbz += strUtil.vString(rs2.getString("lastname"));
							}
						}
					 }
				}
				out.print("<td align='center'>"+sgbz+"</td>");//施工班组
				
				out.print("<td align='center'>"+rs.getString("kgsj")+"</td>");//入场时间
				/**out.print("<td align='center'></td>");//设备到货时间
				out.print("<td align='center'></td>");//交铺时间
				out.print("<td align='center'></td>");//项目现状
				out.print("<td align='center'></td>");//项目进度
				
				out.print("<td align='center'></td>");//给水试压
				out.print("<td align='center'></td>");//排水管道走向
				out.print("<td align='center'></td>");//防水区域试水
				out.print("<td align='center'></td>");//楼梯踏步图片
				out.print("<td align='center'></td>");//电柜绝缘测试
				out.print("<td align='center'></td>");//完工天花内检查
				
				out.print("<td align='center'></td>");//热水器/空调设备调试
				out.print("<td align='center'></td>");//防鼠验收
				out.print("<td align='center'></td>");//油烟机及管道验收
				out.print("<td align='center'></td>");//空调保养单位验收
				*/
				out.print("<td align='center'>"+rs.getString("wcsj18")+"</td>");//竣工图纸
				out.print("<td align='center'>"+rs.getString("wcsj20")+"</td>");//竣工资料
				out.print("<td align='center'>"+rs.getString("wcsj19")+"</td>");//竣工图片
				//out.print("<td align='center'></td>");//移交维修部情况
				//out.print("<td align='center'></td>");//备注
				out.print("</tr>");
			}
		%>
		<tr>
			<td colspan="12" align="right" ><%=SystemEnv.getHtmlLabelName(20087,user.getLanguage())+"："+currentDate%></td>
		</tr>
	</tbody>
</table>
<%
	}
%>